﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Runtime.InteropServices;

/// <summary>
/// Summary description for NetworkInfo
/// </summary>
public class NetworkInfo
{
    static private NetworkInfo _instance;

    static public NetworkInfo Instance
    {
        get
        {
            if (_instance == null)
                _instance = new NetworkInfo();
            return _instance;
        }
    }

    private string _domain;
    private JoinStatus _status;

    public string Domain 
    {
        get { return _domain; } 
    }

    public JoinStatus Status
    {
        get { return _status; }
    }

    private NetworkInfo()
    {
        IntPtr buffer = IntPtr.Zero;
        JoinStatus status;

        NetworkInfoNative.NetGetJoinInformation(Environment.MachineName, out  buffer, out status);

        _status = status;
        _domain = Marshal.PtrToStringUni(buffer);
        if (!IntPtr.Zero.Equals(buffer))
            NetworkInfoNative.NetApiBufferFree(buffer);
    }
}
